﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Caching;
using System.Web;
using System.Web.Mvc;
using Controllerss;
using Core.Contract.DataContract;
using www.Controllerss;
using www.Core.Contract.DataContract;
//using www.SService;

namespace www.Controllers
{
    public class HomeController : Controller
    {
        #region Value
        //private readonly HyServicesClient _sService = new HyServicesClient();
       private readonly DefaultClient _defaultClient=new DefaultClient();
       private readonly StoryController _storyController = new StoryController();
        private readonly PhotoController _photoController=new PhotoController();
        private readonly VideoController _videoController=new VideoController();
        private readonly ContactController _contactController=new ContactController();
        private readonly MenuController _menuController=new MenuController();
        private readonly AdvertiseController _advertiseController=new AdvertiseController();
        private readonly RageComic_MemeController _rageComicMemeController=new RageComic_MemeController();
        private readonly ObjectCache _cache = MemoryCache.Default;
        private readonly Utilities _utilities = new Utilities();
        private const int DefaultPageSize = 20;

        #endregion
        
        #region Flag
        public ActionResult vi_VN(string cul = null)
        {
            Session["LanguageCode"] = 1;
            Session["Culture"] = "vi-VN";
            var url = Request.UrlReferrer;
            var strurl = string.Empty;

            if (url != null)
                strurl = url.LocalPath;
            if (!string.IsNullOrEmpty(strurl))
            {
                if (cul != null) strurl = strurl.Replace(cul, Convert.ToString(Session["Culture"]));
                Response.Redirect(strurl);
            }

            // Mesage(url);
            return RedirectToAction("Index", "Home", new { cul = Session["Culture"] });
        }
        public ActionResult en_US(string cul = null)
        {
            Session["LanguageCode"] = 2;
            Session["Culture"] = "en-US";
            var url = Request.UrlReferrer;
            var strurl = string.Empty;

            if (url != null)
                strurl = url.LocalPath;
            if (!string.IsNullOrEmpty(strurl))
            {
                if (cul != null) strurl = strurl.Replace(cul, Convert.ToString(Session["Culture"]));
                Response.Redirect(strurl);
            }
            return RedirectToAction("Index", "Home", new { cul = Session["Culture"] });
        }
        public ActionResult zh_CN(string cul = null)
        {
            Session["LanguageCode"] = 3;
            Session["Culture"] = "zh-CN";
            var url = Request.UrlReferrer;
            var strurl = string.Empty;

            if (url != null)
                strurl = url.LocalPath;
            if (!string.IsNullOrEmpty(strurl))
            {
                if (cul != null) strurl = strurl.Replace(cul, Convert.ToString(Session["Culture"]));
                Response.Redirect(strurl);
            }
            return RedirectToAction("Index", "Home", new { cul = Session["Culture"] });
        }
        #endregion
        #region Culture

        private void GetCulture(string cul = null)
        {
            if (cul == null && Session["Culture"] == null)
            {
                var languagecode = _utilities.GetLanguageCode();
                Session["LanguageCode"] = languagecode;
                Session["Culture"] = languagecode == 1 ? "vi-VN" : languagecode == 3 ? "zh-CN" : "en-US";
            }
            else
            {
                var culs = Convert.ToString(cul ?? Session["Culture"]);
                Session["LanguageCode"] = culs == "vi-VN" ? 1 : culs == "zh-CN" ? 3 : 2;
                Session["Culture"] = culs;
            }
        }
        #endregion
        #region Get info basic

        private void GetInfoBasic()
        {
            var lMenu = (List<RelaxMenuDataContract>)_cache["Menu"];
            var lAdvertise = (List<RelaxAdvertiseDataContract>)_cache["Advertise"];
            var lVideo = (List<RelaxVideoDataContract>)_cache["Video"];
            if (lMenu == null)
            {
                lMenu = _menuController.GetMenuDataContracts().ToList();
                if (lMenu.Any())
                {
                    var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                    _cache.Set("Menu", lMenu, policy);
                }
            }

            ViewBag.RelaxMenuDataContracts = lMenu.Where(p => p.Active == Constant.Active.Display && p.Type == 1 && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).ToList();
            if (lAdvertise == null)
            {
                lAdvertise = _advertiseController.GetAdvertiseDataContracts().ToList();
                if (lAdvertise.Any())
                {
                    var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                    _cache.Set("Advertise", lAdvertise, policy);
                }

            }

            ViewBag.RelaxAdvertiseDataContracts = lAdvertise.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).ToList();

            if (lVideo == null)
            {
                lVideo = _videoController.GeVideoDataContracts().ToList();
                if (lVideo.Any())
                {
                    var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                    _cache.Set("Video", lVideo, policy);
                }
            }
            ViewBag.RelaxVideoDataContracts = lVideo.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).Skip(0).Take(6).ToList();

        }
        #endregion
        #region GetPaging
        private List<RelaxPhotoDataContract> GetPaginatedPhoto(int page = 1)
        {
            var skipRecords = (page * DefaultPageSize) - (DefaultPageSize - 1);
            skipRecords = skipRecords < 0 ? 0 : skipRecords;
            var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
            if (lPhoto == null)
                lPhoto = new List<RelaxPhotoDataContract>();
            
            return lPhoto.Where(p => p.Active == Constant.Active.Display && p.CategoryId == 6 && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).Skip(skipRecords).
              Take(DefaultPageSize).ToList();
        }
        private List<RelaxPhotoDataContract> GetPaginatedPhotoSexy(int page = 1)
        {
            var skipRecords = (page * DefaultPageSize) - (DefaultPageSize - 1);
            skipRecords = skipRecords < 0 ? 0 : skipRecords;
            var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
            if (lPhoto == null)
                lPhoto = new List<RelaxPhotoDataContract>();
            
            return lPhoto.Where(p => p.Active == Constant.Active.Display && p.CategoryId == 7 && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).Skip(skipRecords).
              Take(DefaultPageSize).ToList();
        }
        private List<RelaxVideoDataContract> GetPaginatedVideo(int page = 1)
        {
            var skipRecords = (page * DefaultPageSize) - (DefaultPageSize - 1);
            skipRecords = skipRecords < 0 ? 0 : skipRecords;
            var lVideo = (List<RelaxVideoDataContract>)_cache["Video"];
            if (lVideo == null)
                lVideo = new List<RelaxVideoDataContract>();
            
            return lVideo.Where(p => p.Active == Constant.Active.Display && p.CategoryId == 8 && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).Skip(skipRecords).
              Take(DefaultPageSize).ToList();
        }
        private List<RelaxStoryDataContract> GetPaginatedNews(int page = 1)
        {
            var skipRecords = (page * DefaultPageSize) - (DefaultPageSize - 1);
            skipRecords = skipRecords < 0 ? 0 : skipRecords;
            var lNews = (List<RelaxStoryDataContract>)_cache["News"];
            if (lNews == null)
                lNews = new List<RelaxStoryDataContract>();
           
            return lNews.Where(p => p.Active == Constant.Active.Display &&
                        p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) &&
                        (p.CategoryId == 9 || p.CategoryId == 10)).OrderByDescending(o => o.Id).Skip(skipRecords).
                Take(DefaultPageSize).ToList();
        }
        private List<RelaxStoryDataContract> GetPaginatedHotNews(int page = 1)
        {
            var skipRecords = (page * DefaultPageSize) - (DefaultPageSize - 1);
            skipRecords = skipRecords < 0 ? 0 : skipRecords;
            var lNews = (List<RelaxStoryDataContract>)_cache["News"];
            if (lNews == null)
                lNews = new List<RelaxStoryDataContract>();
           
            return lNews.Where(p => p.Active == Constant.Active.Display &&
                        p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) &&
                        p.CategoryId == 9).OrderByDescending(o => o.Id).Skip(skipRecords).
                Take(DefaultPageSize).ToList();
        }
        private List<RelaxStoryDataContract> GetPaginatedTechnologyNews(int page = 1)
        {
            var skipRecords = (page * DefaultPageSize) - (DefaultPageSize - 1);
            skipRecords = skipRecords < 0 ? 0 : skipRecords;
            var lNews = (List<RelaxStoryDataContract>)_cache["News"];
            if (lNews == null)
                lNews = new List<RelaxStoryDataContract>();
           
            return lNews.Where(p => p.Active == Constant.Active.Display &&
                        p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) &&
                        p.CategoryId == 10).OrderByDescending(o => o.Id).Skip(skipRecords).
                Take(DefaultPageSize).ToList();
        }
        private List<RelaxStoryDataContract> GetPaginatedStory(int page = 1, long catId = 0)
        {
            var skipRecords = (page * DefaultPageSize) - (DefaultPageSize - 1);
            skipRecords = skipRecords < 0 ? 0 : skipRecords;
            var lNews = (List<RelaxStoryDataContract>)_cache["News"];
            if (lNews == null)
                lNews = new List<RelaxStoryDataContract>();
          
            return lNews.Where(p => p.Active == Constant.Active.Display &&
                        p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) &&
                        p.CategoryId == catId).OrderByDescending(o => o.Id).Skip(skipRecords).
                Take(DefaultPageSize).ToList();
        }
        private List<RelaxStoryDataContract> GetPaginatedAngleSaid(int page = 1, long catId = 0)
        {
            var skipRecords = (page * DefaultPageSize) - (DefaultPageSize - 1);
            skipRecords = skipRecords < 0 ? 0 : skipRecords;
            var lNews = (List<RelaxStoryDataContract>)_cache["News"];
            if (lNews == null)
                lNews = new List<RelaxStoryDataContract>();
           
            return lNews.Where(p => p.Active == Constant.Active.Display &&
                        p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) &&
                        p.CategoryId == catId).OrderByDescending(o => o.Id).Skip(skipRecords).
                Take(DefaultPageSize).ToList();
        }
        private List<RelaxRagcomicMemeDataContract> GetPaginatedRagcomic(int page = 1, int type = 0)
        {
            var skipRecords = (page * DefaultPageSize) - (DefaultPageSize - 1);
            skipRecords = skipRecords < 0 ? 0 : skipRecords;
            var lComic = (List<RelaxRagcomicMemeDataContract>)_cache["Meme"];
            if (lComic == null)
                lComic = new List<RelaxRagcomicMemeDataContract>();

            return lComic.Where(p => p.Active == Constant.Active.Display &&
                        p.Type == type).OrderByDescending(o => o.Id).Skip(skipRecords).
                Take(DefaultPageSize).ToList();
        }
        #endregion
        #region Home

        private void GetDefaultData(ref IEnumerable<RelaxStoryDataContract> storyDataContracts,
            ref IEnumerable<RelaxPhotoDataContract> photoDataContracts,
            ref IEnumerable<RelaxVideoDataContract> videoDataContracts,
            ref IEnumerable<RelaxMenuDataContract> menuDataContracts,
            ref IEnumerable<RelaxAdvertiseDataContract> advertiseDataContracts)
        {
            storyDataContracts = _defaultClient.GetDefaultDataContracts(ref photoDataContracts, ref videoDataContracts, ref menuDataContracts, ref advertiseDataContracts);
           
        }
        public ActionResult Index(string cul = null)
        {
            try
            {
                 IEnumerable<RelaxPhotoDataContract> photoDataContracts = null;
                 IEnumerable<RelaxVideoDataContract> videoDataContracts = null;
                 IEnumerable<RelaxMenuDataContract> menuDataContracts = null;
                 IEnumerable<RelaxAdvertiseDataContract> advertiseDataContracts = null;
                //IEnumerable<RelaxStoryDataContract> storyDataContracts = null;
                GetCulture(cul);
                var lPhotoDataContract = new List<RelaxPhotoDataContract>();

                var policy = new CacheItemPolicy();
                policy.AbsoluteExpiration = DateTimeOffset.Now.AddHours(27);

                if (_cache["News"] == null && _cache["Photo"] != null && _cache["Video"] != null && _cache["Menu"] != null && _cache["Advertise"] != null)
                {
                    var lData =  _defaultClient.GetDefaultDataContracts(ref photoDataContracts, ref videoDataContracts, ref menuDataContracts, ref advertiseDataContracts);
                    //await GetDefaultData(ref storyDataContracts, ref photoDataContracts, ref videoDataContracts,
                    //        ref menuDataContracts, ref advertiseDataContracts);
                    ViewBag.RelaxStoryDataContracts = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && (p.CategoryId == 11 || p.CategoryId == 13))
                             .OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                    _cache.Set("News", lData.ToList(), policy);

                    if (photoDataContracts == null)
                        photoDataContracts = new List<RelaxPhotoDataContract>();
                   
                    lPhotoDataContract = photoDataContracts.Where(p => p.Active == Constant.Active.Display && p.CategoryId == 6 && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).Skip(0).Take(30).ToList();
                    _cache.Set("Photo", photoDataContracts, policy);

                    if (videoDataContracts == null)
                        videoDataContracts = new List<RelaxVideoDataContract>();
                   
                    ViewBag.RelaxVideoDataContracts = videoDataContracts.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).Skip(0).Take(6).ToList();

                    _cache.Set("Video", videoDataContracts, policy);

                    if (menuDataContracts == null)
                        menuDataContracts = new List<RelaxMenuDataContract>();
                    ViewBag.RelaxMenuDataContracts = menuDataContracts.Where(p => p.Active == Constant.Active.Display && p.Type == 1 && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).ToList();
                    _cache.Set("Menu", menuDataContracts, policy);

                    if (advertiseDataContracts == null)
                        advertiseDataContracts = new List<RelaxAdvertiseDataContract>();
                   
                    ViewBag.RelaxAdvertiseDataContracts = advertiseDataContracts.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).ToList();
                    _cache.Set("Advertise", advertiseDataContracts, policy);

                }
                else
                {
                    var lData = (List<RelaxStoryDataContract>)_cache["News"];
                    var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];

                    if (lData == null)
                    {
                       lData = _storyController.GetStoryDataContracts().ToList();
                        if (lData.Any())
                        {
                            _cache.Set("News", lData, policy);
                        }
                    }
                   
                    ViewBag.RelaxStoryDataContracts = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && (p.CategoryId == 11 || p.CategoryId == 13))
                            .OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();
                    if (lPhoto == null)
                    {
                        lPhoto = _photoController.GePhotoDataContracts().ToList();
                        if (lPhoto.Any())
                        {
                            _cache.Set("Photo", lPhoto, policy);
                        }
                    }
                   
                    //ViewBag.RelaxPhotoDataContracts = lphotos.Skip(0).Take(30).ToList();
                    lPhotoDataContract = lPhoto.Where(p => p.Active == Constant.Active.Display && p.CategoryId == 6 && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).Skip(0).Take(30).ToList();
                    GetInfoBasic();
                }
                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblTitle");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblKeywordDefault");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblDecriptionDefault");

                return View(lPhotoDataContract);
            }
            catch (Exception)
            {
            }
            return View();
        }

        public ActionResult GetPhotoDataContract(int page)
        {
            return PartialView("ImgComicPartial", GetPaginatedPhoto(page));
        }
        public ActionResult GetPhotoSexyDataContract(int page)
        {
            return PartialView("ImgComicPartial", GetPaginatedPhotoSexy(page));
        }
        #endregion
        #region News
        public ActionResult News(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                        var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }
             
                ViewBag.RelaxStoryDataContracts = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && (p.CategoryId == 13 || p.CategoryId == 14))
                        .OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblTitleNews");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblKeywordNews");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblDecriptionNews");

                return View(lData.Where(
                        p => p.Active == Constant.Active.Display &&
                            p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) &&
                            (p.CategoryId == 9 || p.CategoryId == 10)).OrderByDescending(o => o.Id).Take(DefaultPageSize).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }

        public ActionResult GetNewsDataContract(int page)
        {
            return PartialView("_AjaxNewsList", GetPaginatedNews(page));
        }
        public ActionResult HotNews(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
                var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
                if (lPhoto == null)
                {
                    lPhoto = _photoController.GePhotoDataContracts().ToList();
                    if (lPhoto.Any())
                    {
                        var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("Photo", lPhoto, policy);
                    }
                }
              
                ViewBag.RelaxPhotoDataContracts = lPhoto.Where(p => p.Active == Constant.Active.Display && (p.CategoryId == 6 || p.CategoryId == 7) && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                        var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }
               
                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblTitleHotNews");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblDecriptionHotNews");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblKeywordHotNews");

                return View(lData.Where(
                        p => p.Active == Constant.Active.Display &&
                            p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) &&
                            p.CategoryId == 9).OrderByDescending(o => o.Id).Take(DefaultPageSize).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }

        public ActionResult GetHotNewsDataContract(int page)
        {
            return PartialView("_AjaxNewsList", GetPaginatedHotNews(page));
        }

        public ActionResult TechnologyNews(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();

                var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
                if (lPhoto == null)
                {
                    lPhoto = _photoController.GePhotoDataContracts().ToList();
                    if (lPhoto.Any())
                    {
                        var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("Photo", lPhoto, policy);
                    }
                }
                
                ViewBag.RelaxPhotoDataContracts = lPhoto.Where(p => p.Active == Constant.Active.Display && (p.CategoryId == 6 || p.CategoryId == 7) && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                        var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }
                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblTitleTechnologyNews");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblDecriptionTechlonogyNews");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblKeywordTechlonogyNews");

                return View(lData.Where(
                        p => p.Active == Constant.Active.Display &&
                            p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) &&
                            p.CategoryId == 10).OrderByDescending(o => o.Id).Take(DefaultPageSize).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult GetTechnologyNewsDataContract(int page)
        {
            return PartialView("_AjaxNewsList", GetPaginatedTechnologyNews(page));
        }
        public ActionResult NewsDetail(string cul, long catId = 0, long id = 0)
        {
            try
            {
                if (id <= 0)
                    return RedirectToAction("Index", "Home", new { cul = Session["Culture"] });
                GetCulture(cul);
                GetInfoBasic();

                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                        var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }
               
                ViewBag.RelaxNewsDataContracts = lData.Where(
                         p => p.Active == Constant.Active.Display &&
                             p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) &&
                             p.CategoryId == catId).OrderByDescending(o => o.Id).Distinct().Skip(0).Take(20).ToList();

                var firsordefault =
                   lData.FirstOrDefault(
                       p => p.Active == Constant.Active.Display && p.Id == id &&
                           p.Languagecode == Convert.ToInt32(Session["LanguageCode"]));
               
                if (firsordefault != null)
                {
                    _storyController.UpdateView(id);
                    firsordefault.View += 1;
                    _cache["News"] = lData;
                    ViewBag.Title = firsordefault.Name;
                    ViewBag.Decription = firsordefault.Decription;
                    ViewBag.Keyword = firsordefault.Keyword;
                }
                else
                {
                    ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblTitleNews");
                }
                return View(firsordefault);
            }
            catch (Exception)
            {
            }
            return View();
        }
        #endregion
        #region Photo

        public ActionResult Photo(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
                var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
                if (lPhoto == null)
                {
                    lPhoto = _photoController.GePhotoDataContracts().ToList();
                    if (lPhoto.Any())
                    {
                       var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("Photo", lPhoto, policy);
                    }
                }
                var lphotos = lPhoto.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]))
                        .OrderByDescending(o => o.Id);

                ViewBag.RelaxPhotoDataContracts = lphotos.Where(p => p.CategoryId == 7).Distinct().Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblTitlePhoto");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblKeywordPhoto");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblDecriptionPhoto");

                return View(lphotos.Where(p => p.CategoryId == 6).Take(DefaultPageSize).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }

        public ActionResult PhotoComic(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();

                var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
                if (lPhoto == null)
                {
                    lPhoto = _photoController.GePhotoDataContracts().ToList();
                    if (lPhoto.Any())
                    {
                        var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("Photo", lPhoto, policy);
                    }
                }
                var lphotos = lPhoto.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]))
                        .OrderByDescending(o => o.Id);

                ViewBag.RelaxPhotoDataContracts = lphotos.Where(p => p.CategoryId == 7).Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblTitlePhoto");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblKeywordPhoto");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblDecriptionPhoto");

                return View(lphotos.Where(p => p.CategoryId == 6).Take(DefaultPageSize).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult PhotoSexy(string cul)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
                var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
                if (lPhoto == null)
                {
                    lPhoto = _photoController.GePhotoDataContracts().ToList();
                    if (lPhoto.Any())
                    {
                       var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("Photo", lPhoto, policy);
                    }
                }
                var lphotos = lPhoto.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]))
                        .OrderByDescending(o => o.Id);

                ViewBag.RelaxPhotoDataContracts = lphotos.Where(p => p.CategoryId == 6).Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblTitleNews");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblKeywordNews");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblDecriptionNews");

                return View(lphotos.Where(p => p.CategoryId == 7).Take(DefaultPageSize).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }

        public ActionResult PhotoDetail(string cul = null, long id = 0, Int32 index = 0)
        {
            try
            {
                if (id <= 0)
                    return RedirectToAction("Index", "Home");
                GetCulture();
                GetInfoBasic();
                var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
                if (lPhoto == null)
                {
                    lPhoto = _photoController.GePhotoDataContracts().ToList();
                    if (lPhoto.Any())
                    {
                       var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("Photo", lPhoto, policy);
                    }
                }
                var photo = new RelaxPhotoDataContract();
                var lphotos = lPhoto.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).ToList();

                if (index > 0)
                {
                    index = index >= lphotos.Count ? 0 : index;
                    photo = lphotos[index];
                    var firstordefault = lPhoto.FirstOrDefault(p => p.Id == photo.Id && p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]));
                    if (firstordefault != null)
                    {
                        _photoController.UpdateView(id);
                        firstordefault.View += 1;
                        _cache["Photo"] = lPhoto;
                    }
                }
                else
                {
                    var firstordefault = lPhoto.FirstOrDefault(p => p.Id == id && p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]));
                   
                    if (firstordefault != null)
                    {
                        _photoController.UpdateView(id);
                        firstordefault.View += 1;
                        _cache["Photo"] = lPhoto;
                        photo = firstordefault;
                    }
                   
                }

                return View(photo);
            }
            catch (Exception)
            {
            }
            return View();
        }

        public ActionResult Back(string cul, long id)
        {
            try
            {
                var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
                if (lPhoto == null)
                {
                    lPhoto = _photoController.GePhotoDataContracts().ToList();
                    if (lPhoto.Any())
                    {
                       var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("Photo", lPhoto, policy);
                    }
                }
                var lphotos = lPhoto.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).ToList();

                return RedirectToAction("PhotoDetail", "Home", new { cul = cul, id = id, index = (lphotos.IndexOf(lphotos.FirstOrDefault(p => p.Id == id)) - 1) });

            }
            catch (Exception)
            {
            }

            return RedirectToAction("Photo", "Home", new { cul = cul });
        }
        public ActionResult Next(string cul, long id)
        {
            try
            {
                var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
                if (lPhoto == null)
                {
                    lPhoto = _photoController.GePhotoDataContracts().ToList();
                    if (lPhoto.Any())
                    {
                       var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("Photo", lPhoto, policy);
                    }
                }
                var lphotos = lPhoto.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).ToList();

                return RedirectToAction("PhotoDetail", "Home", new { cul = cul, id = id, index = (lphotos.IndexOf(lphotos.FirstOrDefault(p => p.Id == id)) + 1) });
            }
            catch (Exception)
            {
            }
            return RedirectToAction("Photo", "Home");
        }

        public ActionResult ListPhoto(string cul, string keySearch)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
                var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
                if (lPhoto == null)
                    lPhoto = new List<RelaxPhotoDataContract>();

                var lphotos = lPhoto.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]))
                      .OrderByDescending(o => o.Id);

                ViewBag.RelaxPhotoDataContracts = lphotos.Where(p => p.CategoryId == 7 || p.CategoryId == 6).Skip(0).Take(30).ToList();

                return View(lphotos.Where(p => Utility.ConvertToUnSign(p.Name).ToLower().Contains(Utility.ConvertToUnSign(keySearch).ToLower())).Distinct().OrderByDescending(o=>o.Id).Skip(0).Take(100).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }
        #endregion
        #region Video
        public ActionResult Video(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
                var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
                if (lPhoto == null)
                    lPhoto = new List<RelaxPhotoDataContract>();

                ViewBag.PhotoComic = lPhoto.Where(p => p.Active == Constant.Active.Display &&
                            p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.Image != null && (p.CategoryId == 6 || p.CategoryId == 7)).Distinct().OrderByDescending(o => o.Id).Skip(0).Take(5).ToList();

                var lVideo = (List<RelaxVideoDataContract>)_cache["Video"];
                if (lVideo == null)
                {
                    lVideo = _videoController.GeVideoDataContracts().ToList();
                    if (lVideo.Any())
                    {
                        var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("Video", lVideo, policy);
                    }
                }

                var lvideo = lVideo.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).ToList();
                
                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblVideoTitle");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblVideoDecription");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblVideoKeyword");

                return View(lvideo.Skip(0).Take(DefaultPageSize).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult GetVideooDataContract(int page)
        {
            return PartialView("VideoPartial", GetPaginatedVideo(page));
        }
        public ActionResult VideoDetail(string cul, long id = 0, Int32 index = 0)
        {
            try
            {
                if (id <= 0)
                    return RedirectToAction("Index", "Home", new { cul = Session["Culture"] });
                GetCulture(cul);
                GetInfoBasic();
                var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
                if (lPhoto == null)
                    lPhoto = new List<RelaxPhotoDataContract>();

                ViewBag.PhotoComic = lPhoto.Where(p => p.Active == Constant.Active.Display &&
                            p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.Image != null && (p.CategoryId == 6 || p.CategoryId == 7)).Distinct().OrderByDescending(o => o.Id).Skip(0).Take(5).ToList();

                var lVideo = (List<RelaxVideoDataContract>)_cache["Video"];
                if (lVideo == null)
                {
                    lVideo = _videoController.GeVideoDataContracts().ToList();
                    if (lVideo.Any())
                    {
                        var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("Video", lVideo, policy);
                    }
                }
                var video = new RelaxVideoDataContract();
                var lVideos = lVideo.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).ToList();

                if (index > 0)
                {
                    index = index >= lVideos.Count ? 0 : index;
                    video = lVideos[index];
                    var firstordefault = lVideo.FirstOrDefault(p => p.Id == video.Id && p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]));
                    if (firstordefault != null)
                    {
                        _storyController.UpdateView(id);
                        firstordefault.View += 1;
                        _cache["Video"] = lVideo;
                    }
                }
                else
                {
                    var firstordefault = lVideo.FirstOrDefault(p => p.Id == id && p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]));

                    if (firstordefault != null)
                    {
                        _videoController.UpdateView(id);
                        firstordefault.View += 1;
                        _cache["Video"] = lVideo;
                        video = firstordefault;
                    }
                }
                if (video != null)
                {
                    ViewBag.Title = video.Name;
                    ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblVideoDecription");
                    ViewBag.Keyword = video.Name;
                }
                else
                {
                    ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblVideoTitle");
                }
                return View(video);
            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult VideoBack(string cul, long id)
        {
            try
            {
                var lVideo = (List<RelaxVideoDataContract>)_cache["Video"];
                if (lVideo == null)
                {
                    lVideo = _videoController.GeVideoDataContracts().ToList();
                    if (lVideo.Any())
                    {
                       var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("Video", lVideo, policy);
                    }
                }
                var lVideos = lVideo.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).ToList();
                
                return RedirectToAction("VideoDetail", "Home", new { cul = cul, id = id, index = (lVideos.IndexOf(lVideos.FirstOrDefault(p => p.Id == id)) - 1) });
            }
            catch (Exception)
            {
            }
            return RedirectToAction("Video", "Home", new { cul = cul });
        }
        public ActionResult VideoNext(string cul, long id)
        {
            try
            {
                var lVideo = (List<RelaxVideoDataContract>)_cache["Video"];
                if (lVideo == null)
                {
                    lVideo = _videoController.GeVideoDataContracts().ToList();
                    if (lVideo.Any())
                    {
                       var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("Video", lVideo, policy);
                    }
                }
                var lVideos = lVideo.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"])).OrderByDescending(o => o.Id).ToList();

                return RedirectToAction("VideoDetail", "Home", new { cul = cul, id = id, index = (lVideos.IndexOf(lVideos.FirstOrDefault(p => p.Id == id)) + 1) });

            }
            catch (Exception)
            {
            }
            return RedirectToAction("Video", "Home", new { cul = cul });
        }
        public ActionResult ListVideo(string cul, string keySearch)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
                var lVideo = (List<RelaxVideoDataContract>)_cache["Video"];
                if (lVideo == null)
                    lVideo = new List<RelaxVideoDataContract>();

                return View(lVideo.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && Utility.ConvertToUnSign(p.Name).ToLower().Contains(Utility.ConvertToUnSign(keySearch).ToLower())).Distinct().OrderByDescending(o => o.Id).Skip(0).Take(100).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }

        #endregion
        #region Read Story

        public ActionResult Story(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();

                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                      var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }

                var lStory = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]))
                        .OrderByDescending(o => o.Id);

                ViewBag.ComicStory = lStory.Where(p => p.CategoryId == 13).OrderByDescending(o => o.Id).Skip(0).Take(10).ToList();
                ViewBag.LoveStory = lStory.Where(p => p.CategoryId == 11).OrderByDescending(o => o.Id).Skip(0).Take(10).ToList();
                ViewBag.ShortStory = lStory.Where(p => p.CategoryId == 12).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();
                ViewBag.VovaAndGhost = lStory.Where(p => p.CategoryId == 14 || p.CategoryId == 15).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryTitle");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryDecription");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryKeyword");

            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult StoryComic(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                       var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }
                var lStory = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]))
                        .OrderByDescending(o => o.Id);

                ViewBag.Vova = lStory.Where(p => p.CategoryId == 14).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryTitle");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryDecription");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryKeyword");

                return View(lStory.Where(p => p.CategoryId == 13).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }

        public ActionResult GetStoryComicDataContract(int page)
        {
            return PartialView("StoryComicPartial", GetPaginatedStory(page, 13));
        }
        public ActionResult StoryLove(string cul)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();

                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                      var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }

                ViewBag.AngleSaid = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 16).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryTitle");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryDecription");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryKeyword");

                return View(lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 11).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult GetStoryLoveDataContract(int page)
        {
            return PartialView("StoryLovePartial", GetPaginatedStory(page, 11));
        }
        public ActionResult StoryShort(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();

                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                      var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }

                ViewBag.AngleSaidFamily = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && (p.CategoryId == 18 || p.CategoryId == 17)).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryTitle");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryDecription");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryKeyword");

                return View(lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 12).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult GetStoryShortDataContract(int page)
        {
            return PartialView("StoryShortPartial", GetPaginatedStory(page, 12));
        }
        public ActionResult StoryVova(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();

                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                      var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }

                ViewBag.StoryComic = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 13).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryTitle");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryDecription");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryKeyword");

                return View(lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 14).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList());
            }
            catch (Exception)
            {

            }
            return View();
        }
        public ActionResult GetStoryVovaDataContract(int page)
        {
            return PartialView("StoryVovaAndGhostPartial", GetPaginatedStory(page, 14));
        }
        public ActionResult StoryGhost(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();

                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                       var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }

                ViewBag.StoryShort = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 12).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryTitle");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryDecription");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryKeyword");

                return View(lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 15).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult GetStoryGhostDataContract(int page)
        {
            return PartialView("StoryVovaAndGhostPartial", GetPaginatedStory(page, 15));
        }
        public ActionResult StoryDetail(string cul, long catId = 0, long id = 0)
        {
            if (id <= 0)
                return RedirectToAction("Index", "Home", new { cul = Session["Culture"] });
            GetCulture(cul);
            GetInfoBasic();

            var lData = (List<RelaxStoryDataContract>)_cache["News"];
            if (lData == null)
            {
                lData = _storyController.GetStoryDataContracts().ToList();
                if (lData.Any())
                {
                    var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                    _cache.Set("News", lData, policy);
                }
            }

            ViewBag.StoryCategory = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == catId).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();
            var firsordefault = lData.FirstOrDefault(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.Id == id);
            if (firsordefault != null)
            {
                _storyController.UpdateView(id);
                firsordefault.View += 1;
                _cache["News"] = lData;
                ViewBag.Title = firsordefault.Name;
                ViewBag.Decription = firsordefault.Decription;
                ViewBag.Keyword = firsordefault.Keyword;
            }
            else
            {
                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryTitle");
            }
            return View(firsordefault);
        }
        public ActionResult List(string cul, string keySearch)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();

                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                    lData = new List<RelaxStoryDataContract>();

                ViewBag.StorySearch = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && (p.CategoryId == 14 || p.CategoryId == 11 || p.CategoryId == 12 || p.CategoryId == 13 || p.CategoryId == 15)).OrderByDescending(o => o.Id).Skip(0).Take(30).ToList();

                return View(lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && Utility.ConvertToUnSign(p.Name).ToLower().Contains(Utility.ConvertToUnSign(keySearch).ToLower())).OrderByDescending(o => o.Id).Skip(0).Take(100).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }
        #endregion
        #region Angle Said
        public ActionResult AngleSaid(string cul)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();

                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                       var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }

                var lStory = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]))
                        .OrderByDescending(o => o.Id);

                ViewBag.AngleSaidLove = lStory.Where(p => p.CategoryId == 16).OrderByDescending(o => o.Id).Skip(0).Take(10).ToList();
                ViewBag.AngleSaidFamily = lStory.Where(p => p.CategoryId == 17).OrderByDescending(o => o.Id).Skip(0).Take(10).ToList();
                ViewBag.AngleSaidWorkplace = lStory.Where(p => p.CategoryId == 18).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();
                ViewBag.AngleSaidPregnancy = lStory.Where(p => p.CategoryId == 19).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidTitle");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidDecription");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidKeyword");

            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult AngleSaidLove(string cul)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();

                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                       var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }

                ViewBag.StoryLove = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 11).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidTitle");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidDecription");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidKeyword");

                return View(lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 16).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult GetAngleSaidLoveDataContract(int page)
        {
            return PartialView("AngleSaidLovePartial", GetPaginatedAngleSaid(page, 16));
        }
        public ActionResult AngleSaidFamily(string cul)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                       var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }
               
                ViewBag.StoryShort = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 12).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidTitle");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidDecription");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidKeyword");

                return View(lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 17).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult GetAngleSaidFamilyDataContract(int page)
        {
            return PartialView("AngleSaidFamilyPartial", GetPaginatedAngleSaid(page, 17));
        }
        public ActionResult AngleSaidWorkplace(string cul)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();

                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                       var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }

                ViewBag.StoryComic = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 13).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidTitle");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidDecription");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidKeyword");

                return View(lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 18).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }

        public ActionResult GetAngleSaidWorkplaceDataContract(int page)
        {
            return PartialView("AngleSaidWorkplacePartial", GetPaginatedAngleSaid(page, 18));
        }
        public ActionResult AngleSaidPregnancy(string cul)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();

                var lData = (List<RelaxStoryDataContract>)_cache["News"];
                if (lData == null)
                {
                    lData = _storyController.GetStoryDataContracts().ToList();
                    if (lData.Any())
                    {
                      var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("News", lData, policy);
                    }
                }

                ViewBag.AngleSaidFamily = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 17).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();

                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidTitle");
                ViewBag.Decription = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidDecription");
                ViewBag.Keyword = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidKeyword");

                return View(lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == 19).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult GetAngleSaidPregnancyDataContract(int page)
        {
            return PartialView("AngleSaidPregnancyPartial", GetPaginatedAngleSaid(page, 19));
        }
        public ActionResult AngleSaidDetail(string cul, long catId = 0, long id = 0)
        {
            if (id <= 0)
                return RedirectToAction("Index", "Home", new { cul = Session["Culture"] });
            GetCulture(cul);
            GetInfoBasic();

            var lData = (List<RelaxStoryDataContract>)_cache["News"];
            if (lData == null)
            {
                lData = _storyController.GetStoryDataContracts().ToList();
                if (lData.Any())
                {
                   var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                    _cache.Set("News", lData, policy);
                }
            }

            ViewBag.AngleSaidCategory = lData.Where(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.CategoryId == catId).OrderByDescending(o => o.Id).Skip(0).Take(20).ToList();
            var firsordefault = lData.FirstOrDefault(p => p.Active == Constant.Active.Display && p.Languagecode == Convert.ToInt32(Session["LanguageCode"]) && p.Id == id);
            if (firsordefault != null)
            {
                _storyController.UpdateView(id);
                firsordefault.View += 1;
                _cache["News"] = lData;
                ViewBag.Title = firsordefault.Name;
                ViewBag.Decription = firsordefault.Decription;
                ViewBag.Keyword = firsordefault.Keyword;
            }
            else
            {
                ViewBag.Title = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidTitle");
            }
            return View(firsordefault);
        }
        #endregion

        #region Contact
        public ActionResult Contact(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();

                if (_cache["Contact"] == null)
                {
                    var lData = _contactController.GetContactDataContracts();
                    if (lData.Any())
                    {
                        var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                        _cache.Set("Contact", lData.ToList(), policy);
                    }
                }
            }
            catch (Exception)
            {
            }
            var lData1 = (List<RelaxContactDataContract>)_cache["Contact"];
            if (lData1 == null)
                lData1 = new List<RelaxContactDataContract>();
            return View(lData1.FirstOrDefault(p => p.Type == 1 && p.Active == Constant.Active.Display));

        }
        public ActionResult Send(FormCollection collection)
        {
            try
            {
                var name = collection["txtName"];
                var company = collection["txtCompany"];
                var address = collection["txtAddress"];
                var tel = collection["txtTel"];
                var email = collection["txtEmail"];
                var detail = collection["txtDetail"];
                if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(company) || string.IsNullOrEmpty(address) ||
                    string.IsNullOrEmpty(tel) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(detail))
                {
                    Mesage(Utility.GetResource.GetResouceValue(Session["Culture"], "lblMessageContact"));
                    return RedirectToAction("Contact");
                }
                Int32 sdt;
                if (!int.TryParse(tel, out sdt))
                {
                    Mesage(Utility.GetResource.GetResouceValue(Session["Culture"], "lblMessageContact"));
                    return RedirectToAction("Contact");
                }
                var contact = new RelaxContactDataContract
                {
                    Name = name,
                    Company = company,
                    Address = address,
                    Tel = tel,
                    Active = 0,
                    Date = DateTime.Now,
                    Detail = HttpUtility.HtmlEncode(detail),
                    Email = email,
                    Type = 2,
                    IsAnswer = 0
                };
                var id = _contactController.Add(contact);
                if (id > 0)
                {
                    ViewBag.Message = Utility.GetResource.GetResouceValue(Session["Culture"], "lblSendInfo");
                    var lData = (List<RelaxContactDataContract>)_cache["Contact"];
                    if (lData == null)
                        lData = new List<RelaxContactDataContract>();
                    contact.Id = id;
                    lData.Add(contact);
                    _cache["Contact"] = lData;
                }
            }
            catch (Exception)
            {
            }

            return RedirectToAction("Contact");
        }

        public ActionResult Introduce(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
            }
            catch (Exception)
            {
            }
            return View();
        }

        public ActionResult Policy(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult FAQ(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult Rules(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
            }
            catch (Exception)
            {
            }
            return View();
        }

        #endregion

        #region Post

        public ActionResult Post(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
            }
            catch (Exception)
            {
            }
            return View();
        }
        [HttpGet]
        public ActionResult PostImage(string cul = null)
        {
            try
            {
                if (!Convert.ToBoolean(Session["Success"]))
                {
                    Session["check"] = 1;
                    return RedirectToAction("Login", "Account");
                }
                GetCulture(cul);
                GetInfoBasic();
                var listItemsList = new List<SelectListItem>
                   {
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblImageComic"), Value = "6", Selected = true},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblImageSexy"), Value = "7"}
                   };
                ViewBag.Typeimage = listItemsList;
            }
            catch (Exception)
            {
            }
            return View();
        }
        [HttpPost]
        public ActionResult PostImage(FormCollection collection)
        {
            try
            {
                GetCulture();
                GetInfoBasic();

                var listItemsList = new List<SelectListItem>
                   {
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblImageComic"), Value = "6", Selected = true},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblImageSexy"), Value = "7"}
                   };
                ViewBag.Typeimage = listItemsList;

                var reqCookies = Request.Cookies["timepost"];
                if (reqCookies != null)
                {
                    if (Convert.ToInt32(reqCookies["times"]) > 7)
                    {
                        ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblmaxPost");
                        // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblmaxPost") + "');</script>");
                        return View();
                    }
                    if (((DateTime.Now.Hour * 60 + DateTime.Now.Minute) - Convert.ToInt32(reqCookies["hour"])) < 1)
                    {
                        ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblspacehour");
                        // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblspacehour") + "');</script>");
                        return View();
                    }
                }

                var file = Request.Files;
                if (file == null)
                {
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblMessagePostImage");
                    //Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblMessagePostImage") + "');</script>");
                    return View();
                }
                var name = collection["txtName"];
                if (string.IsNullOrEmpty(name))
                {
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblTitle");
                    // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblTitle") + "');</script>");
                    return View();
                }

                name = name.Replace("'", "");

                var detail = string.Empty;
                var path = "Images/ImgComic/";
                var img = string.Empty;
                if (file.Count == 1)
                {
                    var httpPostedFileBase = file[0];

                    if (httpPostedFileBase != null)
                    {
                        var lenght = httpPostedFileBase.ContentLength;
                        if (lenght > 5242880)
                        {
                            ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblImagelengh");
                            // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblImagelengh") + "');</script>");
                            return View();
                        }
                        var ext = new FileInfo(httpPostedFileBase.FileName).Extension;
                        var filename = httpPostedFileBase.FileName.Substring(0,
                            httpPostedFileBase.FileName.IndexOf(ext, StringComparison.Ordinal));
                        var fn = Convert.ToString(Session["UserId"]) + "_" + DateTime.Now.Year + "_" +
                                 DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "_" +
                                 DateTime.Now.Minute + "_" + DateTime.Now.Second + "_" + DateTime.Now.Ticks;
                        filename = httpPostedFileBase.FileName.Replace(filename, fn);
                        img = path + filename;
                        httpPostedFileBase.SaveAs(Server.MapPath("~/" + img));
                    }
                    else
                    {
                        ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"],
                            "lblMessagePostImage");
                        // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblMessagePostImage") + "');</script>");
                        return View();
                    }
                }
                else if (file.Count > 1)
                {
                    var lenght = 0.0;
                    for (var i = 0; i < file.Count; i++)
                    {
                        var httpPostedFileBase = file[i];

                        if (httpPostedFileBase != null)
                        {
                            lenght += httpPostedFileBase.ContentLength;
                        }
                    }
                    if (lenght > 5242880)
                    {
                        ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblImagelengh");
                        // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblImagelengh") + "');</script>");
                        return View();
                    }
                    for (var i = 0; i < file.Count; i++)
                    {
                        var httpPostedFileBase = file[i];
                        if (httpPostedFileBase != null)
                        {
                            var ext = new FileInfo(httpPostedFileBase.FileName).Extension;
                            var filename = httpPostedFileBase.FileName.Substring(0,
                                httpPostedFileBase.FileName.IndexOf(ext, StringComparison.Ordinal));
                            var fn = Convert.ToString(Session["UserId"]) + "_" + DateTime.Now.Year + "_" +
                                     DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "_" +
                                     DateTime.Now.Minute + "_" + DateTime.Now.Second + "_" + DateTime.Now.Ticks;
                            filename = httpPostedFileBase.FileName.Replace(filename, fn);

                            httpPostedFileBase.SaveAs(Server.MapPath("~/" + path + filename));
                            detail += "<img src='/" + path + filename + "' alt='" + name + "' /> <br />";
                        }
                    }
                }

                var imgpost = new RelaxPhotoDataContract
                {
                    Active = 2,
                    Name = name,
                    Tag = name.Replace(' ', '-'),
                    Priority = 1,
                    Languagecode = Convert.ToInt32(Session["LanguageCode"]),
                    Detail = HttpUtility.HtmlEncode(detail),
                    Image = img,
                    IsDefault = 0,
                    View = 0,
                    Date = DateTime.Now,
                    CategoryId = Convert.ToInt32(collection["Typeimage"]),
                    Userid = Convert.ToInt32(Session["UserId"]),
                    Report = 0,
                    UserBrower = 0
                };
                var id = _photoController.Add(new List<RelaxPhotoDataContract> { imgpost });
                if (id > 0)
                {
                    var lData = (List<RelaxPhotoDataContract>)_cache["Photo"];
                    if (lData == null)
                        lData = new List<RelaxPhotoDataContract>();
                    imgpost.Id = id;
                    lData.Add(imgpost);

                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblPostSuccess");
                    _cache["Photo"] = lData;
                    var ck = new HttpCookie("timepost");
                    ck["times"] = (Convert.ToInt32(reqCookies == null ? "0" : reqCookies["times"] ?? "0") + 1).ToString();
                    ck["hour"] = (DateTime.Now.Hour * 60 + DateTime.Now.Minute).ToString();
                    Response.Cookies.Add(ck);
                }
            }
            catch (Exception)
            {
            }

            return View();
        }
        [HttpGet]
        public ActionResult PostVideo(string cul = null)
        {
            try
            {
                if (!Convert.ToBoolean(Session["Success"]))
                {
                    Session["check"] = 2;
                    return RedirectToAction("Login", "Account");
                }
                GetCulture(cul);
                GetInfoBasic();
                var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
                if (lPhoto == null)
                    lPhoto = new List<RelaxPhotoDataContract>();
                var lPhotos =
                    lPhoto.Where(
                        p =>
                            p.Active == Constant.Active.Display &&
                            p.Languagecode == Convert.ToInt32(Session["LanguageCode"]))
                        .OrderByDescending(o => o.Id)
                        .ToList();
                ViewBag.PhotoComic = lPhotos.Where(p => p.CategoryId == 6 || p.CategoryId == 7).ToList();

            }
            catch (Exception)
            {
            }
            return View();
        }
        [HttpPost]
        public ActionResult PostVideo(FormCollection collection)
        {
            try
            {
                GetCulture();
                GetInfoBasic();
                var lPhoto = (List<RelaxPhotoDataContract>)_cache["Photo"];
                if (lPhoto == null)
                    lPhoto = new List<RelaxPhotoDataContract>();
                var lPhotos =
                    lPhoto.Where(
                        p =>
                            p.Active == Constant.Active.Display &&
                            p.Languagecode == Convert.ToInt32(Session["LanguageCode"]))
                        .OrderByDescending(o => o.Id)
                        .ToList();
                ViewBag.PhotoComic = lPhotos.Where(p => p.CategoryId == 6 || p.CategoryId == 7).ToList();

                var reqCookies = Request.Cookies["timepostVideo"];
                if (reqCookies != null)
                {
                    if (Convert.ToInt32(reqCookies["times"]) > 7)
                    {
                        ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblmaxPost");
                        // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblmaxPost") + "');</script>");
                        return View();
                    }
                    if (((DateTime.Now.Hour * 60 + DateTime.Now.Minute) - Convert.ToInt32(reqCookies["hour"])) < 1)
                    {
                        ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblspacehour");
                        // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblspacehour") + "');</script>");
                        return View();
                    }
                }
                var name = collection["txtName"];
                var url = collection["txtUrl"];
                if (string.IsNullOrEmpty(name))
                {
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblTitle");
                    // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblTitle") + "');</script>");
                    return View();
                }
                if (string.IsNullOrEmpty(url))
                {
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblUrl");
                    return View();
                }
                if (!url.Contains("www.youtube.com"))
                {
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblErrorUrl");
                    return View();
                }
                var code = url.IndexOf('?') > 0
                    ? url.Substring(url.IndexOf("v=") + 2)
                    : null;
                if (string.IsNullOrEmpty(code))
                {
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblErrorUrl1");
                    return View();
                }
                var ytCode = code.IndexOf('&') > 0 ? code.Substring(0, code.Length - (code.IndexOf('&') + 2)) : code;
                name = name.Replace("'", "");
                var advertise = new RelaxVideoDataContract
                {
                    Active = 2,
                    Priority = 1,
                    Name = name,
                    Tag = name.Replace(' ', '-'),
                    Code = ytCode,
                    Languagecode = Convert.ToInt32(Session["LanguageCode"]),
                    IsDefault = 0,
                    CategoryId = 8,
                    Userid = Convert.ToInt32(Session["UserId"]),
                    Date = DateTime.Now,
                    Report = 0,
                    View = 0
                };
                var id = _videoController.Add(new List<RelaxVideoDataContract> { advertise });
                if (id > 0)
                {
                    var lData = (List<RelaxVideoDataContract>)_cache["Video"];
                    if (lData == null)
                        lData = new List<RelaxVideoDataContract>();
                    advertise.Id = id;
                    lData.Add(advertise);
                    _cache["Video"] = lData;
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblPostSuccess");
                    var ck = new HttpCookie("timepostVideo");
                    ck["times"] = (Convert.ToInt32(reqCookies == null ? "0" : reqCookies["times"] ?? "0") + 1).ToString();
                    ck["hour"] = (DateTime.Now.Hour * 60 + DateTime.Now.Minute).ToString();
                    Response.Cookies.Add(ck);
                }
            }
            catch (Exception)
            {
            }
            return View();
        }
        [HttpGet]
        public ActionResult PostStory(string cul = null)
        {
            try
            {
                if (!Convert.ToBoolean(Session["Success"]))
                {
                    Session["check"] = 3;
                    return RedirectToAction("Login", "Account");
                }
                GetCulture(cul);
                GetInfoBasic();
                var listItemsList = new List<SelectListItem>
                   {
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryLove"), Value = "11", Selected = true},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryShort"), Value = "12"},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryComic"), Value = "13"},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryVova"), Value = "14"},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryGhost"), Value = "15"}
                   };
                ViewBag.StoryType = listItemsList;
            }
            catch (Exception)
            {
            }
            return View();
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult PostStory(FormCollection collection)
        {
            try
            {
                GetCulture();
                GetInfoBasic();
                var listItemsList = new List<SelectListItem>
                   {
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryLove"), Value = "11", Selected = true},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryShort"), Value = "12"},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryComic"), Value = "13"},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryVova"), Value = "14"},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblStoryGhost"), Value = "15"}
                   };
                ViewBag.StoryType = listItemsList;

                var reqCookies = Request.Cookies["timepostStory"];
                if (reqCookies != null)
                {
                    if (Convert.ToInt32(reqCookies["times"] ?? "0") > 7)
                    {
                        ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblmaxPost");
                        // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblmaxPost") + "');</script>");
                        return View();
                    }
                    if (((DateTime.Now.Hour * 60 + DateTime.Now.Minute) - Convert.ToInt32(reqCookies["hour"] ?? "0")) < 1)
                    {
                        ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblspacehour");
                        // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblspacehour") + "');</script>");
                        return View();
                    }
                }
                var path = "Images/News/";
                var categoryId = collection["StoryType"];
                var name = collection["txtName"];
                var summary = collection["txtSummary"];
                var detail = collection["txtdetail"];
                var file = Request.Files["fufile"];
                if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(summary) || string.IsNullOrEmpty(detail) ||
                    file == null)
                {
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblRequire");
                    return View();
                }
                if (string.IsNullOrEmpty(file.FileName))
                {
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblMessagePostImage");
                    return View();
                }
                name = name.Replace("'", "");
                var ext = new FileInfo(file.FileName).Extension;
                var filename = file.FileName.Substring(0,
                    file.FileName.IndexOf(ext, StringComparison.Ordinal));
                var fn = Convert.ToString(Session["UserId"]) + "_" + DateTime.Now.Year + "_" +
                         DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "_" +
                         DateTime.Now.Minute + "_" + DateTime.Now.Second + "_" + DateTime.Now.Ticks;
                filename = file.FileName.Replace(filename, fn);
                var advertise = new RelaxStoryDataContract
                {
                    Active = 2,
                    Name = name,
                    Tag = name.Replace(' ', '-'),
                    Decription = summary,
                    Priority = 1,
                    Keyword = name,
                    Languagecode = Convert.ToInt32(Session["LanguageCode"]),
                    Detail = HttpUtility.HtmlEncode(detail),
                    IsDefault = 0,
                    View = 0,
                    Image = path + filename,
                    Date = DateTime.Now,
                    CategoryId = Convert.ToInt32(categoryId),
                    Userid = Convert.ToInt32(Session["UserId"]),
                    Report = 0,
                    UserBrower = 0
                };
                var id = _storyController.Add(new List<RelaxStoryDataContract> { advertise });
                if (id > 0)
                {
                    var lData = (List<RelaxStoryDataContract>)_cache["News"];
                    if (lData == null)
                        lData = new List<RelaxStoryDataContract>();
                    advertise.Id = id;
                    lData.Add(advertise);
                    _cache["News"] = lData;
                    file.SaveAs(Server.MapPath("~/" + path + filename));
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblPostSuccess");

                    var ck = new HttpCookie("timepostStory");
                    ck["times"] = (Convert.ToInt32(reqCookies == null ? "0" : reqCookies["times"] ?? "0") + 1).ToString();
                    ck["hour"] = (DateTime.Now.Hour * 60 + DateTime.Now.Minute).ToString();
                    Response.Cookies.Add(ck);
                }

            }
            catch (Exception)
            {
                ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblDecription");
            }
            return View();
        }
        [HttpGet]
        public ActionResult PostAngleSaid(string cul = null)
        {
            try
            {
                if (!Convert.ToBoolean(Session["Success"]))
                {
                    Session["check"] = 4;
                    return RedirectToAction("Login", "Account");
                }
                GetCulture(cul);
                GetInfoBasic();
                var listItemsList = new List<SelectListItem>
                   {
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidLove"), Value = "16", Selected = true},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidFamily"), Value = "17"},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidWorkplace"), Value = "18"},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidPregnancy"), Value = "19"}
                   };
                ViewBag.AngleSaidType = listItemsList;
            }
            catch (Exception)
            {
            }
            return View();
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult PostAngleSaid(FormCollection collection)
        {
            try
            {
                if (!Convert.ToBoolean(Session["Success"]))
                {
                    Session["check"] = 4;
                    return RedirectToAction("Login", "Account");
                }
                GetCulture();
                GetInfoBasic();
                var listItemsList = new List<SelectListItem>
                   {
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidLove"), Value = "16", Selected = true},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidFamily"), Value = "17"},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidWorkplace"), Value = "18"},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblAngleSaidPregnancy"), Value = "19"}
                   };
                ViewBag.AngleSaidType = listItemsList;

                var reqCookies = Request.Cookies["timepostAngleSaid"];
                if (reqCookies != null)
                {
                    if (Convert.ToInt32(reqCookies["times"] ?? "0") > 7)
                    {
                        ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblmaxPost");
                        // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblmaxPost") + "');</script>");
                        return View();
                    }
                    if (((DateTime.Now.Hour * 60 + DateTime.Now.Minute) - Convert.ToInt32(reqCookies["hour"] ?? "0")) < 1)
                    {
                        ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblspacehour");
                        // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblspacehour") + "');</script>");
                        return View();
                    }
                }

                var path = "Images/News/";
                var categoryId = collection["AngleSaidType"];
                var name = collection["txtName"];
                var summary = collection["txtSummary"];
                var detail = collection["txtdetail"];
                var file = Request.Files["fufile"];
                if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(summary) || string.IsNullOrEmpty(detail) ||
                    file == null)
                {
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblRequire");
                    return View();
                }
                if (string.IsNullOrEmpty(file.FileName))
                {
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblMessagePostImage");
                    return View();
                }
                name = name.Replace("'", "");
                var ext = new FileInfo(file.FileName).Extension;
                var filename = file.FileName.Substring(0,
                    file.FileName.IndexOf(ext, StringComparison.Ordinal));
                var fn = Convert.ToString(Session["UserId"]) + "_" + DateTime.Now.Year + "_" +
                         DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "_" +
                         DateTime.Now.Minute + "_" + DateTime.Now.Second + "_" + DateTime.Now.Ticks;
                filename = file.FileName.Replace(filename, fn);
                var advertise = new RelaxStoryDataContract
                {
                    Active = 2,
                    Name = name,
                    Tag = name.Replace(' ', '-'),
                    Decription = summary,
                    Priority = 1,
                    Keyword = name,
                    Languagecode = Convert.ToInt32(Session["LanguageCode"]),
                    Detail = HttpUtility.HtmlEncode(detail),
                    IsDefault = 0,
                    View = 0,
                    Image = path + filename,
                    Date = DateTime.Now,
                    CategoryId = Convert.ToInt32(categoryId),
                    Userid = Convert.ToInt32(Session["UserId"]),
                    Report = 0,
                    UserBrower = 0
                };
                var id = _storyController.Add(new List<RelaxStoryDataContract> { advertise });
                if (id > 0)
                {
                    var lData = (List<RelaxStoryDataContract>)_cache["News"];
                    if (lData == null)
                        lData = new List<RelaxStoryDataContract>();
                    advertise.Id = id;
                    lData.Add(advertise);
                    _cache["News"] = lData;
                    file.SaveAs(Server.MapPath("~/" + path + filename));
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblPostSuccess");

                    if (reqCookies != null)
                    {
                        var ck = new HttpCookie("timepostAngleSaid");
                        ck["times"] = (Convert.ToInt32(reqCookies["times"]) + 1).ToString();
                        ck["hour"] = (DateTime.Now.Hour * 60 + DateTime.Now.Minute).ToString();
                        Response.Cookies.Add(ck);
                    }
                }
            }
            catch (Exception)
            {
                ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblDecription");
            }
            return View();
        }
        [HttpGet]
        public ActionResult PostNews(string cul = null)
        {
            try
            {
                if (!Convert.ToBoolean(Session["Success"]))
                {
                    Session["check"] = 5;
                    return RedirectToAction("Login", "Account");
                }
                GetCulture(cul);
                GetInfoBasic();
                var listItemsList = new List<SelectListItem>
                   {
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblNewsHot"), Value = "9", Selected = true},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblNewsTechnology"), Value = "10"}
                   };
                ViewBag.NewsType = listItemsList;
            }
            catch (Exception)
            {
            }
            return View();
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult PostNews(FormCollection collection)
        {
            try
            {
                GetCulture();
                GetInfoBasic();
                var listItemsList = new List<SelectListItem>
                   {
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblNewsHot"), Value = "9", Selected = true},
                       new SelectListItem {Text = Utility.GetResource.GetResouceValue(Session["Culture"], "lblNewsTechnology"), Value = "10"}
                   };
                ViewBag.NewsType = listItemsList;

                var reqCookies = Request.Cookies["timepostNews"];
                if (reqCookies != null)
                {
                    if (Convert.ToInt32(reqCookies["times"] ?? "0") > 7)
                    {
                        ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblmaxPost");
                        // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblmaxPost") + "');</script>");
                        return View();
                    }
                    if (((DateTime.Now.Hour * 60 + DateTime.Now.Minute) - Convert.ToInt32(reqCookies["hour"] ?? "0")) < 1)
                    {
                        ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblspacehour");
                        // Response.Write("<script>alert('" + Utility.GetResource.GetResouceMessage(Session["Culture"], "lblspacehour") + "');</script>");
                        return View();
                    }
                }

                var path = "Images/News/";
                var categoryId = collection["NewsType"];
                var name = collection["txtName"];
                var summary = collection["txtSummary"];
                var detail = collection["txtdetail"];
                var file = Request.Files["fufile"];
                if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(summary) || string.IsNullOrEmpty(detail) ||
                    file == null)
                {
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblRequire");
                    return View();
                }
                if (string.IsNullOrEmpty(file.FileName))
                {
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblMessagePostImage");
                    return View();
                }
                name = name.Replace("'", "");
                var ext = new FileInfo(file.FileName).Extension;
                var filename = file.FileName.Substring(0,
                    file.FileName.IndexOf(ext, StringComparison.Ordinal));
                var fn = Convert.ToString(Session["UserId"]) + "_" + DateTime.Now.Year + "_" +
                         DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "_" +
                         DateTime.Now.Minute + "_" + DateTime.Now.Second + "_" + DateTime.Now.Ticks;
                filename = file.FileName.Replace(filename, fn);
                var advertise = new RelaxStoryDataContract
                {
                    Active = 2,
                    Name = name,
                    Tag = name.Replace(' ', '-'),
                    Decription = summary,
                    Priority = 1,
                    Keyword = name,
                    Languagecode = Convert.ToInt32(Session["LanguageCode"]),
                    Detail = HttpUtility.HtmlEncode(detail),
                    IsDefault = 0,
                    View = 0,
                    Image = path + filename,
                    Date = DateTime.Now,
                    CategoryId = Convert.ToInt32(categoryId),
                    Userid = Convert.ToInt32(Session["UserId"]),
                    Report = 0,
                    UserBrower = 0
                };
                var id = _storyController.Add(new List<RelaxStoryDataContract> { advertise });
                if (id > 0)
                {
                    var lData = (List<RelaxStoryDataContract>)_cache["News"];
                    if (lData == null)
                        lData = new List<RelaxStoryDataContract>();
                    advertise.Id = id;
                    lData.Add(advertise);
                    _cache["News"] = lData;
                    file.SaveAs(Server.MapPath("~/" + path + filename));
                    ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblPostSuccess");

                    var ck = new HttpCookie("timepostNews");
                    ck["times"] = (Convert.ToInt32(reqCookies == null ? "0" : reqCookies["times"] ?? "0") + 1).ToString();
                    ck["hour"] = (DateTime.Now.Hour * 60 + DateTime.Now.Minute).ToString();
                    Response.Cookies.Add(ck);
                }
            }
            catch (Exception)
            {
                ViewBag.Message = Utility.GetResource.GetResouceMessage(Session["Culture"], "lblDecription");
            }
            return View();
        }
        #endregion

        #region Rage commic
        [HttpGet]
        public ActionResult Ragecomic(string cul = null)
        {
            try
            {
                if (!Convert.ToBoolean(Session["Success"]))
                {
                    Session["check"] = 6;
                    return RedirectToAction("Login", "Account");
                }
                GetCulture(cul);
                GetInfoBasic();
                var lData = _rageComicMemeController.GetRagcomicMemeDataContracts();
                if (lData.Any())
                {
                    var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                    _cache.Set("Meme", lData.ToList(), policy);
                }
                var lData1 = (List<RelaxRagcomicMemeDataContract>)_cache["Meme"];
                if(lData1==null)
                    lData1=new List<RelaxRagcomicMemeDataContract>();
                return View(lData1.Where(p=>p.Active==Constant.Active.Display && p.Type==0).OrderByDescending(o=>o.Id).Skip(0).Take(50).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult GetRagcomicDataContract(int page)
        {
            return PartialView("ComicPartial", GetPaginatedRagcomic(page));
        }
        [HttpPost]
        public ActionResult Ragecomic(FormCollection collection)
        {
            try
            {
                GetCulture();
                GetInfoBasic();
            }
            catch (Exception)
            {
            }
            return View();
        }
        public ActionResult GetMemeDataContract(int page)
        {
            return PartialView("ComicPartial", GetPaginatedRagcomic(page,1));
        }
        [HttpGet]
        public ActionResult Meme(string cul = null)
        {
            try
            {
                if (!Convert.ToBoolean(Session["Success"]))
                {
                    Session["check"] = 7;
                    return RedirectToAction("Login", "Account");
                }
                GetCulture(cul);
                GetInfoBasic();
                var lData = _rageComicMemeController.GetRagcomicMemeDataContracts();
                if (lData.Any())
                {
                    var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(27) };
                    _cache.Set("Meme", lData.ToList(), policy);
                }
                var lData1 = (List<RelaxRagcomicMemeDataContract>)_cache["Meme"];
                if (lData1 == null)
                    lData1 = new List<RelaxRagcomicMemeDataContract>();
                return View(lData1.Where(p => p.Active == Constant.Active.Display && p.Type == 0).OrderByDescending(o => o.Id).Skip(0).Take(50).ToList());
            }
            catch (Exception)
            {
            }
            return View();
        }


        #endregion

        #region Search
        [HttpGet]
        public ActionResult Search(string cul = null)
        {
            try
            {
                GetCulture(cul);
                GetInfoBasic();
            }
            catch (Exception)
            {
            }

            return View();
        }
        [HttpPost]
        public ActionResult Search(FormCollection collection)
        {
            try
            {
                var chkrad = collection["rad"];
                var txtsearch = collection["txtSearch"];
                if (string.IsNullOrEmpty(txtsearch))
                {
                    Mesage(Utility.GetResource.GetResouceValue(Session["Culture"], "lblSearchMessage"));
                    return View();
                }
                if (chkrad == "story")
                {
                    return RedirectToAction("List", "Home", new { cul = Session["Culture"], keySearch = txtsearch.Trim() });
                }
                if (chkrad == "video")
                {
                    return RedirectToAction("ListVideo", "Home", new { cul = Session["Culture"], keySearch = txtsearch.Trim() });
                }
                if (chkrad == "image")
                {
                    return RedirectToAction("ListPhoto", "Home", new { cul = Session["Culture"], keySearch = txtsearch.Trim() });
                }
            }
            catch (Exception)
            {
            }
            return View();
        }

        #endregion

        #region get Like Coment fb
        [HttpPost]
        public JsonResult GetLikeComment(string urltxt)
        {
            var web = new WebClient();
            var url = string.Format("https://api.facebook.com/method/fql.query?query=SELECT url, share_count, like_count, comment_count, total_count, click_count FROM link_stat where url='" + urltxt + "'");
            var response = web.DownloadString(url);
            var ds = new DataSet();
            using (var stringReader = new StringReader(response))
            {
                ds = new DataSet();
                ds.ReadXml(stringReader);
            }
            var dt = ds.Tables["link_stat"];
            var website = new UrlDetails();
            website.Url = dt.Rows[0]["url"].ToString();
            website.LikeCount = dt.Rows[0]["like_count"].ToString();
            website.SharedCount = dt.Rows[0]["share_count"].ToString();
            website.CommentCount = dt.Rows[0]["comment_count"].ToString();
            website.ClickCount = dt.Rows[0]["click_count"].ToString();
            website.TotalCount = dt.Rows[0]["total_count"].ToString();

            return Json(website);//, JsonRequestBehavior.AllowGet
        }

        public class UrlDetails
        {
            public string Url { get; set; }
            public string SharedCount { get; set; }
            public string LikeCount { get; set; }
            public string CommentCount { get; set; }
            public string ClickCount { get; set; }
            public string TotalCount { get; set; }
        }
        #endregion

        private void Mesage(string msg)
        {
            Response.Write("<script>alert('"+msg+"');</script>");
        }
    }
}
